﻿<UserControl x:Class="JayDev.MediaScribe.View.Controls.NotesGridControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="200" d:DesignWidth="1000"
             xmlns:atb="clr-namespace:AvalonTextBox;assembly=MediaScribe.AvalonTextBox"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
             xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
             xmlns:local="clr-namespace:JayDev.MediaScribe.View.Controls"
             xmlns:nmConverters="clr-namespace:JayDev.MediaScribe.Converters"
             xmlns:syswin="clr-namespace:System.Windows;assembly=PresentationCore"
             x:Name="NotesGridControlName">
    <UserControl.Resources>
        <!--<nmConverters:NullToVisibilityConverter 
                x:Key="NullToVisibilityConverterNotNullIsVisible" 
                NullValue="Collapsed" 
                NotNullValue="Visible" />-->
    </UserControl.Resources>
    <Grid>
        <local:DelayedBindDataGrid MinWidth="300"
            VirtualizingStackPanel.VirtualizationMode="Recycling"
            VirtualizingStackPanel.IsVirtualizing="True"
            EnableColumnVirtualization="True"
            EnableRowVirtualization="True"
            SelectionMode="Single"  
            AutoGenerateColumns="False" x:Name="noteDataGrid" HeadersVisibility="Column" CanUserSortColumns="True" CanUserResizeRows="False" CanUserAddRows="True"
            CanUserDeleteRows="True" RowEditEnding="noteDataGrid_RowEditEnding" BeginningEdit="noteDataGrid_BeginningEdit"
            PreparingCellForEdit="noteDataGrid_PreparingCellForEdit"
            ItemsSource="{ Binding ElementName=NotesGridControlName, Path=Notes, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, IsAsync=True}"  CellEditEnding="noteDataGrid_CellEditEnding" Style="{StaticResource DataGridStyle1}">
            <DataGrid.InputBindings>
                <KeyBinding Key="Delete" Command="{Binding ElementName=NotesGridControlName, Path=DoNothing}" />
            </DataGrid.InputBindings>
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Remove Note" Command="{Binding ElementName=NotesGridControlName, Path=DeleteSelectedNote}" />
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="From" Width="90" SortMemberPath="Start.StringDisplayValue" CanUserSort="True">
                    <!-- editing template -->
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                <TextBlock Text="{Binding Path=Start.StringDisplayValue}" />
                                <TextBlock xml:space="preserve"></TextBlock>

                                <local:UndecoratedButton Margin="2 0 0 0" VerticalAlignment="Center" Click="setNoteStartTime_Click">
                                <Image Height="15" Width="15">
                                    
                                    <Image.Style>
                                        <Style TargetType="{x:Type Image}">
                                            <Setter Property="Source" Value="/MediaScribe;component/Images/pencil-15.png"/>
                                            <Style.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter Property="Source" Value="/MediaScribe;component/Images/pencil-15-hover2.png"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Image.Style>
                                    </Image>
                                </local:UndecoratedButton>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                    <!-- standard template -->
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>


                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                <local:UndecoratedButton VerticalAlignment="Center" Click="playNoteButton_Click">
                                    <Image>
                                        <Image.Style>
                                            <Style TargetType="{x:Type Image}">
                                                <Setter Property="Source" Value="/MediaScribe;component/Images/miniplaybutton3.png"/>
                                                <Style.Triggers>
                                                    <Trigger Property="IsMouseOver" Value="True">
                                                        <Setter Property="Source" Value="/MediaScribe;component/Images/miniplaybutton3-hover.png"/>
                                                    </Trigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Image.Style>
                                    </Image>
                                </local:UndecoratedButton>
                                <TextBlock Margin="2 0 0 0" Text="{Binding Path=Start.StringDisplayValue}" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Note" Width="*" SortMemberPath="Body" CanUserSort="True">
                    <!-- editing template -->
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <atb:AvalonTextBox MarkedupText="{Binding Path=Body, Mode=TwoWay, UpdateSourceTrigger=LostFocus, TargetNullValue=''}"
                                               FontFamily="Verdana"
                                               FontSize="11"
                                               TextOptions.TextFormattingMode="Display"
                                               
                                               Width="auto" WordWrap="True" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                    <!-- standard template -->
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <atb:BindableTextBlock TextWrapping="Wrap" TextOptions.TextFormattingMode="Display" MarkedupText="{Binding Path=Body}" DefaultText="Double-click here to write a note..." />
                            <!--<TextBlock TextWrapping="Wrap"   TextOptions.TextFormattingMode="Display" Text="{Binding Path=TitleBody}" />-->
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Rating" Width="50" SortMemberPath="Rating" CanUserSort="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Rating}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=Rating}" PreviewTextInput="TextBox_PreviewTextInput" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </local:DelayedBindDataGrid>
    </Grid>
</UserControl>
